package com.acane.instagram.mapper;

import com.acane.instagram.pojo.Collection;
import com.acane.instagram.pojo.Post;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CollectionMapper extends BaseMapper<Collection> {

    @Select("SELECT p.* FROM post p JOIN collections c ON p.id = c.post_id WHERE c.user_id = #{userId}")
    List<Post> getCollectionList(String userId);

    @Select("SELECT * FROM collections WHERE user_id = #{userId} AND post_id = #{postId}")
    List<Collection> judgeCollected(String userId, String postId);

    @Delete("DELETE FROM collections WHERE user_id = #{userId} AND post_id = #{postId}")
    int cancelCollection(String userId, String postId);
}
